package com.fattyCorps.battle.service.battle.behavior.state;

import com.fattyCorps.battle.service.battle.Battle;
import com.fattyCorps.battle.service.battle.behavior.Behavior;
import com.fattyCorps.battle.service.battle.behavior.BhvBlackboard;
import com.fattyCorps.battle.service.battle.data.BattleHero;
import com.fattyCorps.battle.service.battle.effect.Effect;
import com.fattyCorps.common.enums.battle.EBehaviorEffectType;
import com.fattyCorps.common.util.fsm.FsmState;

import java.util.List;

// 执行影响效果
public class SInvokeEffect extends FsmState {
    @Override
    public void onEnter() {
        BattleHero trigger = (BattleHero)getBlackboard(BhvBlackboard.BHV_TRIGGER);
        Battle battle = (Battle)getBlackboard(BhvBlackboard.BATTLE);
        Behavior behavior = (Behavior)getBlackboard(BhvBlackboard.BHV);
        List<Effect> activeEffects = (List<Effect>)getBlackboard(BhvBlackboard.BHV_ACTIVE_EFFECTS);
        BattleHero creator = (BattleHero) getBlackboard(BhvBlackboard.BHV_CREATOR);

        for (Effect activeEffect : activeEffects) {
            // 如果是buff效果，并且是伤害类型的buff，则施加buff的英雄是触发者
            // todo: 如果是buff，并且是增益，临时护罩之类的的buff，则又要把触发人修改本次行为触发人
            if (activeEffect.isBuff()) {
                if (activeEffect.getMould().getType().equals(EBehaviorEffectType.DynamicProp)) {
                    activeEffect.setTrigger(creator);
                } else {
                    throw new RuntimeException("暂时不支持的buff类型");
                }
            } else {
                activeEffect.setTrigger(trigger);
            }
        }

        // 将可用的activeEffects上报给当前出手的管理器
        battle.getEffectProcessor().addAll(activeEffects);
        battle.getBhvProcessor().activeBehavior(behavior);
    }
}
